package com.ktjy.ch07.controller;


import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {


    //跳转到登录的首页
    @GetMapping("/tologin")
    public String tologin() {
        return "login";
    }

    //点击登录执行的方法
    @PostMapping("/loLogin")
    public String loLogin() {
        System.out.println("执行登录方法");
        return "main";
    }

    @PostMapping("/toError")
    public String toError() {
        return "error";
    }

    //@Secured("ROLE_main")
    //@PreAuthorize("hasRole('main')")
    @PreAuthorize("hasAuthority('admin')")
    @RequestMapping("/main")
    public String main() {
        return "main";
    }

}
